package com.googlecode.vanaraha.data
@serializable 
class SourceFile(val sourceIdentifierName : String, 
                 val sourcePath: String) extends Ordered[SourceFile]{ 
  def this(sourcePath: String) = this(sourcePath, sourcePath)
  lazy val srcType = SourceType.toSourceType(sourcePath)
  override def toString = "[SourceFile] identifier = " + this.sourceIdentifierName +
    ", sourcePath = " + this.sourcePath
  
  override def compare(other: SourceFile) = sourceIdentifierName.compareTo(other.sourceIdentifierName)
  override def equals(other: Any) = other match{
    case that:SourceFile => this.sourceIdentifierName == that.sourceIdentifierName
    case _ => false
  }
  lazy val simpleName:String = {
    val path = sourcePath replaceAll("\\\\", "/")
    if(sourcePath.indexOf("/") != -1) 
      sourcePath.substring(sourcePath.lastIndexOf("/") + 1)
    else sourcePath
  }
}

case class EnrichedSourceFile(override val sourceIdentifierName: String, 
                              override val sourcePath: String,
                              rawLineCount: Int, significantLineCount: Int) extends SourceFile(sourceIdentifierName, sourcePath)

object SourceType extends Enumeration{
  val JAVA = Value("java")
  val JSP = Value("jsp") 
  val JS = Value("js")
  val CPP = Value("cpp")
  val CS = Value("cs")
  val NOT_A_SOURCE = Value("not a known source!")  
  
  def toSourceType(s: String) = 
    if(s!=null && s.indexOf(".") != -1){
       val extension = s.toLowerCase.substring(s.lastIndexOf(".")+1, s.length)
       extension match{
         case "java" => JAVA
         case "jsp" => JSP
         case "js" => JS
         case "cpp" => CPP 
         case "cs" => CS
         case _ => NOT_A_SOURCE
       }
    }else NOT_A_SOURCE
}
}